iOS 利用KVO和KVC解决SDCycleScrollView功能缺陷

SDCycleScrollView使用起来非常便利,可能一些小细节会自己的需求不符,在不修改源代码的情况下项目中做了调整来满足UI需求,记录下一下。

解决分页控件不能靠右问题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[[self.adScrollView valueForKeyPath:@"_pageControl"] addObserver:self forKeyPath:@"hidden" options:NSKeyValueObservingOptionNew context:nil];
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
if([keyPath isEqualToString:@"hidden"]) {
UIControl *pageControl = [self.adScrollView valueForKeyPath:@"_pageControl"];
CGRect frame = pageControl.frame;
frame.origin.x = 15;
pageControl.frame = frame;
}
}
// 注销监听
- (void)dealloc{
[[self.adScrollView valueForKeyPath:@"_pageControl"] removeObserver:self forKeyPath:@"hidden"];
}

解决背景图片不能铺满问题

1
2
UIImageView *backgroundImageView = [cycleScrollView valueForKeyPath:@"_backgroundImageView"];
backgroundImageView.contentMode = UIViewContentModeScaleToFill;